package com.kuanter.kuanterauto.view;

import com.kuanter.kuanterauto.utils.DimensUtil;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Align;
import android.util.AttributeSet;
import android.widget.TextView;

/** 
 * @author utopia
 * @version 2013-10-21 上午11:50:06
 * 
 */
public class CircleTextView extends TextView {
	Context context;
	public CircleTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
	}

	public CircleTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
	}

	public CircleTextView(Context context) {
		super(context);
		this.context = context;
	}
	
	String text;
	int radius;
	int textSize;
	public void drawText(String text,int radius,int textSize) {
		this.text = text;
		this.radius = radius;
		this.textSize = textSize;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
	    Rect rect = canvas.getClipBounds();
	    Paint paint = new Paint();
	    paint.setAntiAlias(true);
	    paint.setColor(0xffffffff);
	    canvas.drawCircle(rect.centerX(), rect.centerY(), radius, paint);
	    
	    paint.setColor(Color.parseColor("#CD0066FF"));
	    paint.setTextSize(DimensUtil.dipTopx(context, textSize));
	    paint.setTextAlign(Align.CENTER);
//	    Rect rect1 = new Rect();
//	    super.getPaint().getTextBounds(text, 0, text.length(), rect1);
	    if(text != null) {
	    	canvas.drawText(text, rect.exactCenterX(), rect.exactCenterY() + radius / 2, paint);
	    }
	}
	
	

	
}
